package com.help10000.rms.ui.fragments

import android.os.Bundle
import android.view.View
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.amir.common.beans.WalletData
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.help10000.rms.mvp.presenter.WalletPresenter
import com.help10000.rms.mvp.view.WalletView
import com.help10000.rms.ui.activitys.WalletDetailActivity
import com.help10000.rms.ui.base.BaseFragment
import com.help10000.rms.ui.utils.PageUtils
import kotlinx.android.synthetic.main.fragment_wallet.*


class WalletFragment : BaseFragment<WalletPresenter, WalletView>(), WalletView,
    SwipeRefreshLayout.OnRefreshListener {


    companion object {
        @JvmStatic
        fun newInstance() = WalletFragment()
    }


    override fun lazyLoad() {

    }

    override fun getlayoutId(): Int {
        return R.layout.fragment_wallet
    }

    override fun initView(rootView: View?) {
        //上面的方法已经废弃
        swipeLayout.setColorSchemeColors(
            resources.getColor(R.color.colorPrimary),
            resources.getColor(R.color.colorPrimary),
            resources.getColor(R.color.colorPrimary),
            resources.getColor(R.color.colorPrimary)
        )
    }

    override fun showLoading() {

    }

    override fun dismissLoading() {
        super.dismissLoading()
        swipeLayout.isRefreshing = false
    }

    override fun initData(savedInstanceState: Bundle?) {

    }

    override fun initListener() {
        swipeLayout.setOnRefreshListener(this)
        tv_desc.setOnClickListener(DuplicateClickProxy {
            PageUtils.jumpToActivity(getViewContext(), WalletDetailActivity::class.java)
        })
    }

    override fun walletDataSuccess(data: WalletData) {
        swipeLayout.isRefreshing = false
        tv_balance.text = data.Balance
        tv_currmouthunit.text = "${data.WXYJ_CurrentMonth}/${data.WXDS_CurrentMonth}"
        tv_lastmouthunit.text = "${data.WXYJ_PreMonth}/${data.WXDS_PreMonth}"
        tv_curryearuntil.text = "${data.WXYJ_CurrentYear}/${data.WXDS_CurrentYear}"
        tv_currmouthrework.text =
            "${data.FGYJ_FanGong_CurrentMonth}/${data.WXDS_FanGong_CurrentMonth}"
    }

    override fun createPresenter(): WalletPresenter {
        return WalletPresenter(this)
    }

    override fun onResume() {
        super.onResume()
        mPresenter.getWallData()
    }
    override fun onRefresh() {
        mPresenter.getWallData()
    }
}